<?php
include("../common.inc.php");
InitGP(array("page","action","gid","delids")); //初始化变量全局返回
include("function_common.php");
	//初始化对象
	include(INC_PATH."/guestbook.class.php");
	$gb=new GuestBook();


if(empty($action)){
	InitGP(array("typeid","title")); //初始化变量全局返回
	if(!empty($title))$wherestr[]="msg like '%{$title}%'";
	if(!empty($wherestr)) $wheresql = implode(' AND ', $wherestr);	//条件汇总
	
	//获取当前页码
	$total=$gb->getcount($wheresql); 							  //总信息数
	$pagesize=15;												  //一页显示信息数
	$page = isset($page) ? max(1, intval($page)) : 1;             //处理页码变量
	$offset=($page-1)*$pagesize;   								  //偏移量
	$dataarray=$gb->getdata("$offset,$pagesize",$wheresql); //获取团购数据
	
	//包含后台模板文件
	include("tpl/guestbook_list.htm");
}elseif ($action=="update") {
	//更新状态禁用或者启用
	InitGP(array("gid")); //初始化变量全局返回
	$state=$gb->state($gid)?0:1;
	$gb->state($gid,$state);
	showmsg("设置状态成功!","guestbook_list.php");//成功
}elseif ($action=="edit") {
	InitGP(array("gid","reply","Submit")); //初始化变量全局返回
	if(!empty($Submit)){
		//处理提交动作
		if(isset($gid) && isset($reply)){
		//处理数据
		$gid=GetNum($gid);
		$reply=HtmlReplace($reply,-1);
		//执行回复
		$info=$gb->replay($gid,$reply);
		if($info=="OK"){
			showmsg("回复成功!","guestbook_list.php");//成功
		}else showmsg($info,"-1");//出错！
	}else showmsg("缺少参数","-1");//出错！
		
	}else {
	
	//编辑信息表单
	$dataedit=$gb->getdata(1,"gid={$gid}");
	$value=$dataedit[0];//获取第一条记录
	//包含后台模板文件
	include("tpl/guestbook_list.htm");	
	}
}elseif ($action=="del" && !empty($gid)){
	//执行删除操作
	$gid=GetNum($gid);
	$info=$gb->del($gid);
	if($info=="OK")showmsg("删除留言成功！","guestbook_list.php");
	else showmsg($info,"guestbook_list.php");
}elseif ($action=="dels"){
	if(empty($delids)){showmsg("没有选择任何对象！","guestbook_list.php");exit;}//空选择
	//执行删除多个操作
	foreach ($delids as $id){
		$id=GetNum($id);
		$info=$gb->del($id);
	}
	if($info=="OK")showmsg("删除留言成功！","guestbook_list.php");
	else showmsg($info,"guestbook_list.php");
}

?>

